/**
 * @param {number[][]} land
 * @return {number[][]}
 */
 var findFarmland = function(land) {
  const m = land.length, n = land[0].length
  const ret = []
  const dfs = (i, j, path, rightBottom) => {
    if(i < 0 || i >= m || j < 0 || j >= n || land[i][j] === 0){
      if(path[0] < rightBottom[0]){
        path[0] = rightBottom[0]
      }
      if(path[1] < rightBottom[1]){
        path[1] = rightBottom[1]
      }
      return 
    }
    rightBottom = [i, j]
    land[i][j] = 0
    dfs(i+1, j, path, rightBottom)
    dfs(i, j+1, path, rightBottom)
  }
  for(let i = 0; i<m; i++){
    for(let j = 0; j<n; j++){
      if(land[i][j] === 1){
        const path = [i,j]
        dfs(i,j, path, [i,j])
        ret.push([i, j, ...path])
      }
    }
  }
  return ret
};